package com.ckerchina.admin.ckadmin.service;

import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ckerchina.admin.ckadmin.cache.MemcachedService;
import com.ckerchina.admin.ckadmin.dao.AgentOrderDao;
import com.ckerchina.admin.ckadmin.dao.AppUserDAO;
import com.ckerchina.admin.ckadmin.domain.AgentOrder;
import com.ckerchina.admin.ckadmin.domain.AppUser;

/**
 * Created by 晓丰 on 2015/12/13.
 */
@Service
public class AgentOrderService {

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private AgentOrderDao agentOrderDao;

    private String namespace = AppUser.class.getName();

    @Autowired
    private MemcachedService memcachedService;


 
    
    @Transactional
    public void merge(AgentOrder appUser){
    	agentOrderDao.merge(appUser);
//        memcachedService.setWithNamespace(namespace,String.valueOf(appUser.getId()),appUser);
    }
    
    @Transactional
    public void mergeOrderNum(AgentOrder appUser){
//    	if(appUser.getOrder_num() == null)
//    	{
//    		appUser.setOrder_num(UUID.randomUUID().toString());
    		agentOrderDao.merge(appUser);
//    	}
    	
//        memcachedService.setWithNamespace(namespace,String.valueOf(appUser.getId()),appUser);
    }

    @Transactional
    public void mergeAgentOrder(AgentOrder agentOrder){
    	AgentOrder olduser = agentOrderDao.find(agentOrder.getId());
        if(olduser != null){
        	olduser.setCustomer_request(agentOrder.getCustomer_request());
            merge(olduser);
        }
    }
    
    public synchronized String genOrderNum()
    {
    	 
    	return "";
    }
  
}
